namespace NAct.Attributes
{
	using System;
	using Patterns;

	public abstract class SpecificationBase: Attribute, ISpecification
	{
		protected string pattern;
		protected string prefix;

		public string Pattern
		{
			get { return string.Format( "{0} {1}", prefix, pattern ); }
		}

		public string ValueFor( string token, string text )
		{
			return new PatternMatcher( Pattern ).Parse( text ).Get( token );
		}

		public virtual bool Matches( ScenarioStep step )
		{
			IPatternParseResults parseResults = new PatternMatcher( Pattern ).Parse( step.Text );
			return !string.IsNullOrEmpty( parseResults.Source );
		}
	}
}